using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;


namespace dohoa2
{
    class Chinhchunhat: Chinhve 
    {
        int xx, yy, xx2, yy2;
        int i;
        public Chinhchunhat(Bitmap hinh, Color mn, int x, int y, int x2, int y2)
        {
            anh = hinh;
            maunen = mn;
            xx = x; yy = y; xx2 = x2; yy2 = y2;

        }
        public Chinhchunhat(Bitmap hinh, Color mn, Point mot,Point hai)
        {
            anh = hinh;
            maunen = mn;
            xx = mot.X; yy = mot.Y; xx2 = hai.X; yy2 = hai.Y;

        }

        public override void ve() 
        {
            for (i = xx; i < xx2; i++)
            {
                anh.SetPixel(i, yy, mauve);
                anh.SetPixel(i, yy2, mauve);
            }
            for (i = yy; i < yy2; i++)
            {
                anh.SetPixel(xx, i, mauve);
                anh.SetPixel(xx2, i, mauve);
            }

        }

        public override void vechon()
        {
            veonho(xx, yy);
            veonho(xx2, yy2);
        }
       

        public override bool kiemtraduocchon(Point p)
        {
            if (p.X > xx && p.X < xx2 && p.Y > yy && p.Y < yy2)
                return true;
            return false;
        }

        public override void tinhtien(Point mot, Point hai)
        {
            int dx, dy;
            Color mauluu = new Color();
            mauluu = mauve;
            mauve = maunen;
            try
            {
                ve();
                if (duocchon == true) bochon();
            }
            catch { }

            mauve = mauluu;
            dx = hai.X - mot.X;
            dy = hai.Y - mot.Y;
       
            if ((xx + dx - kichthuoconho / 2 >= 0) && (xx  + dx + kichthuoconho / 2) <= anh.Width
                && (yy  + dy - kichthuoconho / 2) >= 0 && (yy  + dy + kichthuoconho / 2) <= anh.Height 

            )
            {
                xx += dx;
                xx2 += dx;
                yy += dy;
                yy2 += dy;
            }
         
                ve();
                if (duocchon == true) vechon();
          
        }
    }
}
